******************************************************************************************
* Do-file name:	an_reg_wage_indv_03.do                                                   
* Task:         estimate pure wage effect (inc. age in baseline) for non-employed            
* Last change:  04.03.2023                                                               
* Notes: 
/*
This file contains the code used to generate the results presented in the following tables and figures:
- Table 3:
		-- Pure wage effect, Panel A: pe_ne_s1
*/                                                                            
******************************************************************************************



******************************************************************************************
*** program setup
******************************************************************************************

version 14.2
clear all
macro drop _all
set linesize 90
set more off
* set trace on
discard
set seed 123456789
*set matsize 2000



******************************************************************************************
*** load working dataset
******************************************************************************************

use "data/work_indiv.dta", clear

*** restrict sample
keep if nation_gr == 1
keep if impy_2 != .			
keep if ao_gem_imp != .

*** drop variables
drop d_emp_* d_wage_* y_to* 

*** create outcome: price effect
sort vsnr_ano year
tsset vsnr_ano year


** native wage growth: here as price effect (wage growth of stayers in the same region)
foreach y of numlist 1991/1995 {
gen d_wage_nat_`y'_90 = impy2_`y' - impy2_1990  if year == 1990 & nation_gr == 1 & status != 1 & ao_gem_imp_1990 == ao_gem_imp_`y' & ao_gem_imp_1990 != . & ao_gem_imp_`y' != .
	}

*** restrict sample
keep if year == 1990

*** create weight for fte including non-employed individulas
gen 	weight_fte_2 = weight_fte
replace weight_fte_2 = 1  if status != 1



******************************************************************************************
*** set globals
******************************************************************************************

*** baseline controls
global controls_base  "age"

*** baseline restrictions for wage regerssions
global base_restric_wa "(border_imp_13 == 1 | control_imp == 1) & year == 1990 & nation_gr == 1 & age >= 16 & age <= 65 & weight_fte_2 != ."

* 1) 
global restric_wage_1 "$base_restric_wa"
global sample_wage_1  "All non-employed workers (natives)"


*** use different czech shocks
foreach year of numlist 1987/1990 1992/1995 {
global czech_shock_`year' "czshare_92_90_predic_13"
	}

global czech_shock_1991   "czshare_91_90_predic_13"



******************************************************************************************
*** estimate price effect
******************************************************************************************

*** run different samples 
foreach y of numlist 1  {

foreach x of numlist 1993/1995 {

*** 1) basic model
reg d_wage_nat_`x'_90  ${czech_shock_`x'} $controls_base  if ${restric_wage_`y'} [pweight=weight_matching], cluster(ao_kreis_imp)
est store pe_`x'_90_s`y'


*** check sample
dis "Sample: ${sample_wage_`y'}"
dis "Sample: ${restric_wage_`y'}"
dis "Sample restriction version: 16-65, non-employed native stayers"
count if e(sample)


********* bootstrap standard errors ***************************************************************
preserve
keep if e(sample)
drop czshare_92_90_predic_13
forval bs = 1/500 {
	di "bootstrap sample `bs'"
	merge m:1 ao_gem_imp using "data/bootstrap/bs_wild_first_92_`bs'.dta", nogenerate
	reg d_wage_nat_`x'_90  czshare_92_90_predic_13 $controls_base  if ${restric_wage_`y'} [pweight=weight_matching]
	predict res  if e(sample), res
	predict xb   if e(sample), xb
	gen y = xb + wild * res
	qui reg y  czshare_92_90_predic_13  $controls_base  if ${restric_wage_`y'} [pweight=weight_matching]
	scalar coef`bs' = _b[czshare_92_90_predic_13]
	drop y res xb czshare_92_90_predic_13 wild
}
gen bs = . 
gen coef_pe_ne_s`y'_`x' = .
forval bs = 1/500 {
	replace bs = `bs' in `bs'
	replace coef_pe_ne_s`y'_`x' = coef`bs' in `bs'
}
keep bs coef_pe_ne_s`y'_`x'
keep if bs != .
save "data/bootstrap/price_effect\bs_coef_pe_ne_s`y'_`x'.dta", replace
sum coef_pe_ne_s`y'_`x'		// std. dev. = std. error
restore

***************************************************************************************************
	}


*** create tables
#delimit ;
global estout_wage "cells(b(star fmt(%9.3f) vacant(-)) se(fmt(%9.3f) par)) 
stats(N N_clust r2_a, labels("Observations" "Clusters" "Adjusted R2") layout(@ @ @) fmt(%9.0fc %9.0fc %9.3f))
starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30)
varlabels(_cons "Constant" czshare_92_90_predic_13 "Share Czechs (92-90, pred.)" age "Age") label
mlabels("Pr.Ef. 93-90" "Pr.Ef. 94-90" "Pr.Ef. 95-90")
prehead(@title) posthead() postfoot(@note) nonumbers collabels(none) style(tab)";
#delimit cr


** Tables: Price effect
estout 	pe_1993_90_s`y'  pe_1994_90_s`y'  pe_1995_90_s`y' ///
using "tables\price_effect/tab_pe_ne_s`y'.txt", $estout_wage replace ///	
title(Native Wage Growth 1993-1995: Price Effect (Non-Empl), Sample: ${sample_wage_`y'}) ///
note(Notes: Individual approach. Native stayers in region, who are non-employed in 1990, wage imputed. * p<0.1, ** p<0.05, *** p<0.01. ///
Data Source: German Social Security Records, border districts and matched control districts, 1993-1995.)
	}


******************************************************************************************
*** end
******************************************************************************************

exit


*========================================================================================*
Comments:
- unique identifier: vsnr_ano year
